<template>
  <el-form :model="tableCost">
    <el-col
      :span="14"
      class="el-col-offset-2"
    ><el-input
      v-model.trim="tableCost.val"
      clearable
      :disabled="disabled"
      @keyup.native="changeStockValue"
      @focus="changeDisabled"
    /></el-col>
  </el-form>
</template>

<script>
export default {
  name: 'GoodsSalePriceValue',
  props: {
    disabled: {
      type: Boolean,
      required: false
    },
    index: {
      type: Number,
      required: true
    },
    tablePrice: {
      type: Number,
      required: false,
      default: function() {
        return 0
      }
    },
    commodityId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      tableCost: {
        val: ''
      }
    }
  },
  mounted() {
    if (this.tablePrice) {
      this.tableCost.val = this.tablePrice
    }
  },
  methods: {
    getData() {
      const vm = this
      return vm.tableCost.val
    },
    changeDisabled() {
      const vm = this
      vm.$emit('changeStockDisable')
    },
    changeStockValue() {
      if (/^[0-9]*[1-9][0-9]*$/g.test(this.tableCost.val)) {
        if (this.tableCost.val < 0) {
          this.tableCost.val = 0
        } if (this.tableCost.val > 100000) {
          this.tableCost.val = 100000
        }
      } else {
        this.tableCost.val = null
      }
    }
  }
}
</script>

<style scoped>
</style>
